<?php
namespace Admin\Controller;

class CreditController extends AdminBaseController
{
   public function invert()
    {
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $categorys=M('DomainType')->select();
        $this->assign("categorys",$categorys);
        $this->display('credit/invert');
    }
    
    public function invertlist(){
        $domtypeid = I('domtypeid','');
        if($domtypeid!=''){
            $condi['dd_inves_domcate.domtypeid']=$domtypeid;
        }
        $uid=I('uid','');
        if($uid!=''){
            $condi['dd_investor_info.uid']=$uid;
        }
       $InvestorInfodao= M('InvestorInfo');
       $investlist = $InvestorInfodao
        ->join(' LEFT JOIN dd_user_assets on dd_investor_info.uid=dd_user_assets.uid')
        ->join(' LEFT JOIN dd_inves_domcate on dd_investor_info.id=dd_inves_domcate.inve_id')
        ->field('dd_investor_info.id,dd_investor_info.uid,dd_investor_info.term_begin,dd_investor_info.term_end,dd_investor_info.create_time,SUM(dd_investor_info.tovalue) as tovalue,dd_user_assets.creditmoney as money,dd_inves_domcate.rate,dd_inves_domcate.domtypeid,dd_inves_domcate.domtypname,dd_inves_domcate.credit')
        ->where($condi)->group('dd_investor_info.id,dd_inves_domcate.domtypeid')->order("dd_investor_info.create_time desc")->select();
        $count=$InvestorInfodao
        ->join(' LEFT JOIN dd_user_assets on dd_investor_info.uid=dd_user_assets.uid')
        ->join(' LEFT JOIN dd_inves_domcate on dd_investor_info.id=dd_inves_domcate.inve_id')->where($condi)
        ->group('dd_investor_info.id,dd_inves_domcate.domtypeid')->count();
        $map=array(
            'rows'=>$investlist,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }
    
    public function loader()
    {
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $categorys=M('DomainType')->select();
        $this->assign("categorys",$categorys);
        $this->display('credit/loader');
    }
    
    public function loaderlist(){
        $domtypeid = I('domtypeid','');
        if($domtypeid!=''){
            $condi['a.domaintypeid']=$domtypeid;
        }
        $uid=I('uid','');
        if($uid!=''){
            $condi['a.uid']=$uid;
        }
        $LoaderInfo= M('LoaderInfo');
        $loaderlist = $LoaderInfo->join(' as a LEFT JOIN dd_domain_type b on a.domaintypeid=b.id')
        ->field('a.*,b.name')->where($condi)->order("a.create_time desc")->select();
        $count= $LoaderInfo->join(' as a LEFT JOIN dd_domain_type b on a.domaintypeid=b.id')->where($condi)->count();
        $map=array(
            'rows'=>$loaderlist,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }
    
    public function credflow(){
        $this->display('credit/credflow');
    }
    
    public function credflowlist(){
        $loanduid = I('loanduid','');
        if($loanduid!=''){
            $condi['a.loanduid']=$loanduid;
        }
        $investuid = I('investuid','');
        if($investuid!=''){
            $condi['a.investuid']=$investuid;
        }
        $status=I('status','');
        if($status!=''){
            $condi['a.status']=$status;
        }
        $CredFlow= M('CredFlow');
        $loaderlist = $CredFlow->join(' as a LEFT JOIN dd_domain_type b on a.domtypeid=b.id')
        ->field('a.*,b.name')->where($condi)->order("a.createdate desc")->select();
        $count= $CredFlow->join(' as a LEFT JOIN dd_domain_type b on a.domtypeid=b.id')->where($condi)->count();
        $map=array(
            'rows'=>$loaderlist,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }
    
    public function credflowdetail(){
       $id= I('id','');
       
       if($id!=''){
           $condi['a.cred_code']=$id;
       }
       $CredflowDomian= M('CredflowDomian');
       $list = $CredflowDomian->join(' as a LEFT JOIN dd_user_domains b on a.domainid=b.id')
       ->field('a.*,b.domain')->where($condi)->select();
       $this->assign('list',$list);
       $this->display('credit/credflowdetail');
    }
}